﻿#region Header
//
//   Project:           SilverShader - Silverlight pixel shader demo application for Coding4Fun.
//
//   Changed by:        $Author$
//   Changed on:        $Date$
//   Changed in:        $Revision$
//   Project:           $URL$
//   Id:                $Id$
//
//
//   Copyright (c) 2010 Rene Schulte
//
//   This program is open source software. Please read the License.txt.
//
#endregion

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Media3D;


namespace Schulte.Silverlight.Shader
{
   public class ParametricEdgeDetectionShader : ShaderEffect
   {
      #region DependencyProperties

      public static DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ParametricEdgeDetectionShader), 0);
      public static DependencyProperty ThresholdProperty = DependencyProperty.Register("Threshold", typeof(float), typeof(ParametricEdgeDetectionShader), new PropertyMetadata(0.5f, ShaderEffect.PixelShaderConstantCallback(0)));
      public static DependencyProperty K00Property = DependencyProperty.Register("K00", typeof(float), typeof(ParametricEdgeDetectionShader), new PropertyMetadata(1f, ShaderEffect.PixelShaderConstantCallback(1)));
      public static DependencyProperty K01Property = DependencyProperty.Register("K01", typeof(float), typeof(ParametricEdgeDetectionShader), new PropertyMetadata(2f, ShaderEffect.PixelShaderConstantCallback(2)));
      public static DependencyProperty K02Property = DependencyProperty.Register("K02", typeof(float), typeof(ParametricEdgeDetectionShader), new PropertyMetadata(1f, ShaderEffect.PixelShaderConstantCallback(3)));
      public static DependencyProperty TextureSizeProperty = DependencyProperty.Register("TextureSize", typeof(System.Windows.Point), typeof(ParametricEdgeDetectionShader), new PropertyMetadata(new System.Windows.Point(512, 512), ShaderEffect.PixelShaderConstantCallback(4)));
      
      #endregion

      #region Properties

      public virtual System.Windows.Media.Brush Input
      {
         get
         {
            return ((System.Windows.Media.Brush)(GetValue(InputProperty)));
         }
         set
         {
            SetValue(InputProperty, value);
         }
      }

      public virtual float Threshold
      {
         get
         {
            return ((float)(GetValue(ThresholdProperty)));
         }
         set
         {
            SetValue(ThresholdProperty, value);
         }
      }

      public virtual float K00
      {
         get
         {
            return ((float)(GetValue(K00Property)));
         }
         set
         {
            SetValue(K00Property, value);
         }
      }

      public virtual float K01
      {
         get
         {
            return ((float)(GetValue(K01Property)));
         }
         set
         {
            SetValue(K01Property, value);
         }
      }

      public virtual float K02
      {
         get
         {
            return ((float)(GetValue(K02Property)));
         }
         set
         {
            SetValue(K02Property, value);
         }
      }

      public virtual System.Windows.Point TextureSize
      {
         get
         {
            return ((System.Windows.Point)(GetValue(TextureSizeProperty)));
         }
         set
         {
            SetValue(TextureSizeProperty, value);
         }
      }

      #endregion

      #region Contructors

      public ParametricEdgeDetectionShader()
      {
         this.PixelShader = new PixelShader() { UriSource = new Uri("/SilverShader;component/Shaders/ParametricEdgeDetection.ps", UriKind.Relative) };
         this.UpdateShaderValue(InputProperty);
         this.UpdateShaderValue(ThresholdProperty);
         this.UpdateShaderValue(K00Property);
         this.UpdateShaderValue(K01Property);
         this.UpdateShaderValue(K02Property);
         this.UpdateShaderValue(TextureSizeProperty);
      }

      #endregion   
   }
}
